function AccountModel(roles) {
	
	
    var am = this;
    
    this.roles = roles;

    this.getRoles = function() {
        var res = new Object();
        var i = 0;
        for (var key in this.roles) {
            if (this.roles[key].action == "delete") {
                res[this.roles[key].id] = this.roles[key].name;
                i++;
            }
        }
        return res;
    },
    
    this.changeRole = function(id, action, callback) {
        for (var key in this.roles) {
            if (this.roles[key].id == id) {
                this.roles[key].action = action;
                break;
            }
        }
        callback(id);
	},
        
	this.add = function(row) {
		
        var json_data = JSON.stringify({
                email: row.email, 
                name: row.name, 
                phone: row.phone, 
                address: row.address, 
                gender: row.gender,
                drive_length: row.drive_length,
                drive_category: row.drive_category,
                roles: this.getRoles()
            });
        $.ajax({
            type: "POST",
            url: "account_save.htm",
            data: {
                data: json_data
            },
            dataType: "json",
            success: function(response) {
                if (response.res == "false") {
                    alert(response.error);
                }
                window.location.href = "account_item.htm";
            }
        });
	},
    
	
	this.edit = function(row) {
        var json_data = JSON.stringify({
                id: row.id, 
                email: row.email, 
                name: row.name, 
                phone: row.phone, 
                address: row.address, 
                gender: row.gender,
                drive_length: row.drive_length,
                drive_category: row.drive_category,
                roles: this.getRoles()
            });
        $.ajax({
            type: "POST",
            url: "account_save.htm",
            data: {
                data: json_data
            },
            dataType: "json",
            success: function(response) {
                if (response.res == "false") {
                    alert(response.error);
                }
                window.location.href = "account_item.htm";
            }
        });
	}
}